import time

from selenium.webdriver.common.by import By


class PageBackendOrderSearch():
    def __init__(self, driver):
        self.driver = driver

    #输入订单号
    def ele_order_id(self):
        self.driver.find_element(By.ID,'order_sn').send_keys('2021070258363')

     # 点击【搜索】按钮
    def ele_search_submit(self):
        self.driver.find_element(By.ID, 'query').click()

    #点击【查看】按钮
    def ele_find_submit(self):
        self.driver.find_element(By.LINK_TEXT, '查看').click()
        time.sleep(2)

    #点击【确认】按钮
    def ele_affirm_submit(self):
        self.driver.find_element(By.NAME, 'confirm').click()
        time.sleep(2)
    #选中订单号
    def ele_choose_order(self):
        self.driver.find_element(By.NAME, 'checkboxes').click()

    #点击【取消】按钮
    def ele_dismmis_submit(self):
        self.driver.find_element(By.NAME,'cancel').click()


    #输入取消备注
    def ele_dismmis_remark(self):
        self.driver.find_element(By.NAME, 'action_note').send_keys('订单失效')

    #输入取消原因
    def ele_dismmis_reason(self):
        self.driver.find_element(By.ID,'cancel_note').send_keys('未付款')

    #点击【确定】按钮
    def ele_accept_dismmis(self):
        self.driver.find_element(By.NAME, 'submit').click()
    # 进入左侧menuframe
    def ele_menu_frame(self):
        self.driver.switch_to.frame('menu-frame')

    #进入右侧mainframe
    def ele_main_frame(self):
        self.driver.switch_to.frame('main-frame')

    # 退出frame
    def ele_frame_out(self):
        self.driver.switch_to.default_content()


    def backend_search(self):
        self.ele_main_frame()
        self.ele_order_id()
        self.ele_search_submit()
        self.ele_frame_out()

    def order_confirm(self):
        self.ele_main_frame()
        self.ele_order_id()
        self.ele_search_submit()
        self.ele_find_submit()
        self.ele_affirm_submit()
        self.ele_frame_out()

    def order_cancel(self):
        self.ele_main_frame()
        self.ele_order_id()
        self.ele_search_submit()
        self.ele_choose_order()
        self.ele_dismmis_submit()
        self.ele_dismmis_remark()
        self.ele_dismmis_reason()
        self.ele_accept_dismmis()
        self.ele_frame_out()
